//
//  VCForgetPwd.swift
//  AirlineReservation
//
//  Created by Kevin on 2019/12/28.
//  Copyright © 2019 Kevin. All rights reserved.
//

import UIKit

class VCModifyPwd: VCBase {
    
    // 校验View
    lazy var validView: ViewBaseInput = {
        let ui = ViewBaseInput()
        ui.isShowBtn = true
        ui.titleLabel = "确认修改密码"
        ui.backgroundColor = UIColor.white
        ui.nameArrs = [EMAIL,MOBILE,IDNUMBER,NEW_PASSWORD]
        ui.createViews()
        let uiY = realHeight + MARGIN10
        ui.frame = CGRect(x: 0, y: uiY, width: SCREEN_WIDTH, height: SCREEN_HEIGHT - uiY)
        return ui
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // 添加控件
        init_views()
        // 事件监听
        init_event()
    }
}

// MARK: 逻辑部分
extension VCModifyPwd {
    
    func modifyPassowrd(user:UserInfo) -> Void {
        if user.email?.count == 0 {
            self.show(text: "邮箱不能为空")
            return
        }
        if user.mobile?.count == 0 {
            self.show(text: "手机号不能为空")
            return
        }
        if user.idnumber?.count == 0  {
            self.show(text: "身份证号不能为空")
            return
        }
        if user.password?.count == 0  {
            self.show(text: "密码不能为空")
            return
        }
        // 拼数据
        let dict = NSMutableDictionary()
        dict.setValue(user.email, forKey: SP_EMAIL)
        dict.setValue(user.mobile, forKey: SP_MOBILE)
        dict.setValue(user.idnumber, forKey: SP_IDNUMBER)
        dict.setValue(user.password, forKey: SP_PASSWORD)
        // 请求
        self.doPost(api: "foget/password", dict: dict) { (dict) in
            self.show(text: "修改成功")
            self.navigationController?.popViewController(animated: true)
        }
    }
}

// MARK: 初始化
extension VCModifyPwd {
    
    func init_views() -> Void {
        view.addSubview(backroundWhite)
        view.addSubview(validView)
    }
    
    func init_event() -> Void {
        validView.complete = { user in
            self.modifyPassowrd(user: user)
        }
    }
}
